"""
    @Author  ：思念 
    @File    ：5.使用task_done控制进程队列.py
    @Date    ：2025/3/7 14:52 
"""
import time
from multiprocessing import Process,JoinableQueue as Queue


def write(q):
    print("写入进程启动")
    for i in range(4):
        q.put(i)
        print(f"写入{i}")
        time.sleep(0.5)


def read(q):
    print("读取进程启动")
    while True:
        item = q.get()
        print(f"读取{item}")
        q.task_done()


if __name__ == '__main__':
    q = Queue()
    p1 = Process(target=write, args=(q,))
    p2 = Process(target=read, args=(q,))
    p1.start()
    p2.daemon = True
    p2.start()
    p1.join()

